package com.yehuishou.controller;

import java.util.List;

import javax.swing.plaf.synth.SynthStyle;

import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yehuishou.pojo.DescTest;
import com.yehuishou.service.DescTestService;

@Controller
public class DescTestController {

	@Autowired
	private DescTestService dtService;
	
	//查询
	@RequestMapping("desctest")
	public String descAll(@RequestParam(required = true, defaultValue = "1") Integer pageNum,
			@RequestParam(required = true, defaultValue = "10") Integer pageSize,DescTest dt, Model model) {
		PageHelper.startPage(pageNum, pageSize);
		List<DescTest> list = dtService.findAll(dt);
		PageInfo<DescTest> page = new PageInfo<DescTest>(list);
		model.addAttribute("page", page);
		model.addAttribute("dt", dt);
		return "desctest";
	}
	
	//跳转添加
	@RequestMapping("desc-add")
	public String add() {
		return "desc-add";
	}
	
	//添加
	@RequestMapping("descadd")
	/*@ResponseStatus(value=HttpStatus.OK)*/
	public String descadd(DescTest descTest) {
		dtService.save(descTest);
		return "redirect:/desctest";
	}
	
	//删除
	@RequestMapping("descdel")
	@ResponseBody
	public String descdel(Integer id) {
		dtService.del(id);
		return "1";
	}
	
	//跳转查询 descedit
	@RequestMapping("descedit")
	public String descedit(Integer id , Model model) {
		DescTest dt = dtService.findById(id);
		model.addAttribute("dt", dt);
		return "desc-edit";
	}
	
	//修改 descupdate
	@RequestMapping("descupdate")
	public String descupdate(DescTest dt) {
		dtService.update(dt);
		return "redirect:/desctest";
	}
}
